package com.cc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cc.comm.responce.PageResult;
import com.cc.model.dto.SupplierQuery;
import com.cc.model.entity.Suppliers;
import com.cc.mapper.SuppliersMapper;
import com.cc.service.SuppliersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 供应商表 服务实现类
 * </p>
 *
 * @author 晓东√
 * @since 2025-09-19 11:18
 */
@Service
public class SuppliersServiceImpl extends ServiceImpl<SuppliersMapper, Suppliers> implements SuppliersService {
    @Override
    public PageResult<Suppliers> getSupplierPage(SupplierQuery supplierQuery) {
        Page<Suppliers> page = new Page<>(supplierQuery.getPageNum(), supplierQuery.getPageSize());
        LambdaQueryWrapper<Suppliers> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(supplierQuery.getSupplierName()),
                Suppliers::getSupplierName, supplierQuery.getSupplierName())
                .like(StringUtils.isNotBlank(supplierQuery.getContactName()),
                        Suppliers::getContactName, supplierQuery.getContactName())
                .like(StringUtils.isNotBlank(supplierQuery.getContactPhone()),
                        Suppliers::getContactPhone, supplierQuery.getContactPhone());
        return PageResult.of(this.page(page,queryWrapper));
    }
}
